using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class TopSelect : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024find_0024494 : GenericGenerator<WaitForSeconds>
	{
		internal TopSelect _0024self__0024496;

		public _0024find_0024494(TopSelect self_)
		{
			_0024self__0024496 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024496);
		}
	}

	public WorkshopButtons3D Buttons;

	[HideInInspector]
	public bool allowed;

	public Camera textcam;

	public AudioClip clip;

	private ddload ddload;

	public save save;

	private RaycastHit hit;

	private Vector2 pos;

	private Camera mainCamera;

	public string nam;

	private bool ignoreNext;

	public TopSelect()
	{
		nam = "Top1";
	}

	public void Awake()
	{
		StartCoroutine(find());
		mainCamera = FindCamera();
	}

	public void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			pos = UnityEngine.Input.mousePosition;
		}
		if (!allowed || !Input.GetMouseButtonUp(0))
		{
			return;
		}
		Vector3 mousePosition = UnityEngine.Input.mousePosition;
		if (mousePosition.x / pos.x <= 0.95f)
		{
			return;
		}
		Vector3 mousePosition2 = UnityEngine.Input.mousePosition;
		if (mousePosition2.x / pos.x >= 1.05f)
		{
			return;
		}
		Vector3 mousePosition3 = UnityEngine.Input.mousePosition;
		if (mousePosition3.y / pos.y <= 0.95f)
		{
			return;
		}
		Vector3 mousePosition4 = UnityEngine.Input.mousePosition;
		if (mousePosition4.y / pos.y >= 1.05f || !Physics.Raycast(mainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition), out hit, 100f) || !(hit.collider.name != "tops load") || !(hit.collider.name != "buttonblocker"))
		{
			return;
		}
		if (ignoreNext)
		{
			ignoreNext = false;
			return;
		}
		AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
		if (hit.collider.name == "InfoToggle")
		{
			((SpecialAttackInfo)hit.collider.GetComponent(typeof(SpecialAttackInfo))).ShowInfo();
			ignoreNext = true;
		}
		else
		{
			check();
			close();
		}
	}

	public void check()
	{
		nam = hit.collider.name;
		int num = int.Parse(nam.Substring(3));
		ddload.state = num;
		ddload.diskstate = num;
		ddload.basestate = num;
		ddload.chipstate = num;
		Buttons.attackstate = num;
		Buttons.basestate = num;
		Buttons.chipstate = num;
		Buttons.diskstate = num;
		PlayerPrefs.SetInt("AttackState", num);
		PlayerPrefs.SetInt("BaseState", num);
		PlayerPrefs.SetInt("DiskState", num);
		PlayerPrefs.SetInt("ChipState", num);
	}

	public void close()
	{
		ddload.top = nam;
		PlayerPrefs.SetString("SelectedTop", nam);
		save.save();
	}

	public IEnumerator find()
	{
		return new _0024find_0024494(this).GetEnumerator();
	}

	public Camera FindCamera()
	{
		return (!GetComponent<Camera>()) ? Camera.main : GetComponent<Camera>();
	}

	public void Main()
	{
	}
}
